<template>
	<view></view>
</template>
<script>
	export default {
		data() {
			return {
				logintype:'' ,// 跳转来源 0 跳转到设备 1 我的主页
				scode:''
			}
		},
		onLoad(options) {
			this.logintype = options.type;
			this.scode = options.scode;
			this.getlogin();
		},
		methods: {
			getWeiXin() {
				//微信授权跳转
				uni.setNavigationBarTitle({ title:'微信授权跳转' });
				window.location.href = 'http://evcssappapi.yushengkeji.cn/user/v1/getweixincode'
			},
			getlogin(){
				uni.setStorageSync("LoginDate",'');
				let that = this;
				uni.setNavigationBarTitle({ title:'正在登录中' });
				uni.showLoading({
					title:'正在登录中'
				})
				// let openid = uni.getStorageSync("openid");
				let openid="oklcX67Bog5HB6AhCFoGr5yO2R1A"
			
				if(openid) {
					that.http.postJSON({
						url: 'user/v1/login',
						data: {
							"openid": openid,
						}
					}).then((res) => {
						if (res.data.code == 0 && res.data.success == true) {
							uni.setStorageSync("token", res.data.data.token);
							let menuauthority = res.data.data.menuauthority
							uni.setStorageSync("menuauthority",menuauthority);
							uni.setStorageSync("LoginDate",Date.now());
							uni.setStorageSync("usertype",res.data.data.usertype);
							uni.setNavigationBarTitle({ title:'登录成功' });
							if(that.logintype =='device')
							{
								uni.navigateTo({
									url: '/pages/ceshi/device/device?scode='+that.scode
								})
							}
							else if(that.logintype =='yuancheng')
							{
								uni.navigateTo({
									url: '/pages/user/charging/charging'
								})
							}else{
								uni.navigateTo({
									url: '/pages/user/my/my'
								})
							}
						} else {
							that.getWeiXin();
						}
					})
				}
				else
				{
					that.getWeiXin();
				}
			}
		}
	}
</script>		